{% extends 'base.html' %}
{% import '_macros.html' as macros %}

{% block js %}
    <script>
        {% if current_user.is_authenticated %}
            $(function () {
                $('.delete-blog').click(function () {
                    var blog_id = $(this).attr('blog_id');
                    $('.modal-content').load('/blog/delete/' + blog_id);
                    $('#myModal').modal('show')
                });
            });
        {% endif %}
    </script>
{% endblock %}

{% block right %}
    <div class="col-md-12 page-body">
        <div class="row">
            <div class="sub-title">
                <h2>文章归档</h2>
                {% if current_category %}
                / <a>{{ current_category.name }}</a>
                {% endif %}
                <a href="{{ url_for('main.index') }}" title="返回首页"><i class="icon-home"></i></a>
                {% if current_user.is_authenticated %}
                    <a href="{{ url_for('blog.blog_create') }}" target="_blank"><i class="icon-plus"></i></a>
                {% endif %}
            </div>
            <div class="col-md-12 content-page">
                <table class="table table-hover list-table">
                    <tbody>
                    {% for blog in pagination.items %}
                        <tr>
                            <td>
                                <a href="{{ url_for('blog.blog_detail', blog_suffix=blog.url_suffix) }}">{{ blog.title[:30] }}</a>
                            </td>
                            <td>{{ blog.publish_time or '-' }}</td>
                            <td>
                                <a href="{{ url_for('blog.blog_list', category_id=blog.category_id) }}">
                                    {{ blog.category.name }}
                                </a>
                            </td>
                            <td>
                                <i class="icon-eye blue-color"></i>
                                <span>
                                    {{ blog.blogviews.count() }}
                                </span>
                            </td>
                            <td>
                                <i class="glyphicon glyphicon-heart red-color"></i>
                                <span>
                                    {{ blog.bloglikes.count() }}
                                </span>
                            </td>
                            {% if current_user.is_authenticated %}
                                <td>
                                   {{ BLOG_STATUS_DICT.get(blog.status, '-') }}
                                </td>
                                <td>
                                    <a href="{{ url_for('blog.blog_edit', blog_id=blog.id) }}" class="edit-blog"
                                       target="_blank" title="编辑" blog_id="{{ blog.id }}">
                                        <i class="icon-pencil"></i>
                                    </a>
                                    <a href="#" class="delete-blog" title="删除" blog_id="{{ blog.id }}">
                                        <i class="icon-trash"></i>
                                    </a>
                                </td>
                            {% endif %}
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
                <div class="my-pagination">
                    {{ macros.pagination_widget(pagination, 'blog.blog_list') }}
                </div>
            </div>
        </div>
    </div>

    {{ super() }}
{% endblock %}